<?php
	Header('Cache-Control: no-cache');
	Header('Pragma: no-cache');
	Header('X-UA-Compatible: IE=9');
	
	session_start();
?>
<!DOCTYPE html>
<html>
  <head>
    <title>J&auml;ger</title>
	<meta name="viewport"
        content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta charset="UTF-8">
	<link rel="icon" href="icons/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="css/style.css">
  </head>
  <body>
	<?php 
		require_once 'navbar.php';
		
		if (!isset($_SESSION['userid']))
		{
			$db->showMsg(false,"");
			exit;
		}
	?>
	
	<table>
		<tr class="phonelist">
			<th class="left5">Farbe</th>
			<th class="lefty">Name</th>
			<th class="lefty">Vorname</th>
			<th class="lefty">Benutzername</th>
			<th class="left15">Gruppe</th>
			<th class="lefty">Aktion</th>
		</tr>
	<?php
		if (isset($_GET['newhunter']))
		{
			$db->insertHunter();
		}
		else if (isset($_GET['hunteridtodelete']))
		{
			$db->deleteHunter($_GET['hunteridtodelete']);
		}
		
		$res = $db->getHunters();
		$colorRow = true;
		while ($row = $res->fetch_assoc())
		{
			echo '<tr class="phonelist';
			if ($colorRow)
				echo "2";

			echo '">'."\n"
				. '<td style="background-color:'.$row['color'].'"></td>'
				. "<td>".$row['name']."</td>\n"
				. "<td>".$row['firstname']."</td>\n"
				. "<td>".$row['nickname']."</td>\n"
				. "<td>".$row['groupname']."</td>\n"
				. "<td>"
				. '<input type="button" value="Bearbeiten" name="edit" '
				. 'onclick="window.location=\'edithunter.php?id='.$row['id'].'\';" />'."\n"
				. '<input type="button" value="L&ouml;schen" name="delete" '
				. 'onclick="if (confirm(\'J&auml;ger wirklich l&ouml;schen?\')) '
				. 'window.location.search=\'?hunteridtodelete='.$row['id'].'\';" />'."\n"
				. "</td>\n"
				. "</tr>\n";
				
			$colorRow = !$colorRow;
		}
	?>
	</table>
	
	<div class="login">
		<form name="newhunter" action="hunters.php">
			<input type="submit" name="newhunter" value="Neuen J&auml;ger anlegen" />
		</form>
	</div>
  </body>
</html>
